//
//  FFRecvPayUserItemCell.m
//  LLWallet
//
//  Created by tt on 2020/12/23.
//

#import "FFRecvPayUserItemCell.h"

@implementation FFRecvPayUserItemModel

- (Class)cell {
    return FFRecvPayUserItemCell.class;
}

@end

@interface FFRecvPayUserItemCell ()

@property(nonatomic,strong) FFRecvPayUserItemModel *model;

@property(nonatomic,strong) UIView *boxView;

@property(nonatomic,strong) UIImageView *avatarImgView;
@property(nonatomic,strong) UILabel *nameLbl;
@property(nonatomic,strong) UILabel *amountLbl;

@end

@implementation FFRecvPayUserItemCell

+ (CGSize)sizeForModel:(WKFormItemModel *)model {
    return CGSizeMake(WKScreenWidth, 60.0f);
}


- (void)setupUI {
    [super setupUI];
    [self setBackgroundColor:[UIColor clearColor]];
    
    [self.contentView addSubview:self.boxView];
    
    [self.boxView addSubview:self.avatarImgView];
    [self.boxView addSubview:self.nameLbl];
    [self.boxView addSubview:self.amountLbl];
}

- (void)refresh:(FFRecvPayUserItemModel *)model {
    [super refresh:model];
    self.model = model;
    [self.avatarImgView setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[WKApp shared].config.defaultAvatar];
    
    self.nameLbl.text = model.name;
    [self.nameLbl sizeToFit];
    
    self.amountLbl.text = model.amount;
    [self.amountLbl sizeToFit];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.boxView.lim_left = 10.0f;
    self.boxView.lim_width = self.lim_width - self.boxView.lim_left*2.0f;
    self.boxView.lim_height = self.lim_height;
    
    self.boxView.layer.mask = nil;
    if(self.model.bottomCorner) {
        [self setBottomCorner];
    }
    
    self.avatarImgView.lim_left = 15.0f;
    self.avatarImgView.lim_centerY_parent  =self.boxView;
    
    self.nameLbl.lim_left = self.avatarImgView.lim_right + 10.0f;
    self.nameLbl.lim_centerY_parent = self.boxView;
    
    self.amountLbl.lim_left = self.boxView.lim_width - self.amountLbl.lim_width - 15.0f;
    self.amountLbl.lim_centerY_parent = self.boxView;
    
   
}

-(void) setBottomCorner {
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.boxView.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)];
     CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
     maskLayer.frame = self.boxView.bounds;
     maskLayer.path = maskPath.CGPath;
     self.boxView.layer.mask = maskLayer;
}


- (UIView *)boxView {
    if(!_boxView) {
        _boxView = [[UIView alloc] init];
        _boxView.backgroundColor = [UIColor whiteColor];
    }
    return _boxView;
}

- (UIImageView *)avatarImgView {
    if(!_avatarImgView) {
        _avatarImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 40.0f, 40.0f)];
        _avatarImgView.layer.masksToBounds = YES;
        _avatarImgView.layer.cornerRadius = _avatarImgView.lim_height/2.0f;
    }
    return _avatarImgView;
}

- (UILabel *)nameLbl {
    if(!_nameLbl) {
        _nameLbl = [[UILabel alloc] init];
        _nameLbl.textColor = [UIColor colorWithRed:49.0f/255.0f green:49.0f/255.0f blue:49.0f/255.0f alpha:1.0f];
        _nameLbl.font = [[WKApp shared].config appFontOfSize:16.0f];
    }
    return _nameLbl;
}

- (UILabel *)amountLbl {
    if(!_amountLbl) {
        _amountLbl = [[UILabel alloc] init];
        _amountLbl.textColor = [UIColor colorWithRed:49.0f/255.0f green:49.0f/255.0f blue:49.0f/255.0f alpha:1.0f];
        _amountLbl.font = [[WKApp shared].config appFontOfSize:15.0f];
    }
    return _amountLbl;
}

@end
